<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<script type="text/javascript">
    $(function () {
        var clinicIndexId = $("#id").val();
        if (clinicIndexId != null && clinicIndexId != "") {
             selectDoctor($("#deptId").val(), $("#doctorId").val());
        }
    })
    autoCompleteClinic("clinicItemDict");
    function autoCompleteClinic(inputId) {
        var url = "${ctx}/oper/clinicItemDict/automatic?itemClass=L";
        autoComplete(inputId, url,
                function (data) {
                    var rows = [];
                    for (var i = 0; i < data.length; i++) {
                        rows[rows.length] = {
                            data: data[i],
                            value: data[i].id,
                            result: data[i].itemName
                        };
                    }
                    return rows;
                }, function (data, i, max) {
                    return data.itemName + "|" + data.itemCode + "|" + data.price;
                }, function (event, data, formatted) {
                    $("#clinicItemDict1").val(data.id);
                })
    }
    /**
     *  根据科室Id加载医生
     * @param deptId
     */

    function selectDoctor(deptId, doctorId) {
         $.ajax({
            type: "POST",
            url: '${ctx}/sys/orgGroupVsDept/findUserByDeptId?deptId=' + deptId,
            dataType: "json",
            success: function (data) {
                $("#selectId").find("option").remove();
                if (data.length > 0) {
                    $("#selectId").append('<option value="">请选择</option>');
                    for (var i = 0; i < data.length; i++) {
                         var user =data[i];
                        $("#selectId").append('<option value="' + user.id + '">' + user.name + '</option>');
//                        if(user.id==doctorId) {
//                            $("#selectId").val(doctorId).trigger("change");
//                        }
                    }

                } else {
                    $("#selectId").append('<option value="">请选择</option>');
                }
            },
            error: function (data) {
                toastr.error('网络连接错误,请检查网络');
            }
        });
    }
</script>
<div class="content-wrap">
    <div class="wrapper" style="bottom: 50px;">
        <ul class="nav nav-tabs">
            <li>
                <a href="#" onclick="loadDiv('mainCenterDiv','${ctx}/registration/clinicIndex/index')">号别列表</a>
            </li>
            <li class="active">
                <a href="#" onclick="loadDiv('mainCenterDiv','${ctx}/registration/clinicIndex/form')">
                    <c:choose>
                        <c:when test="${clinicIndex.id==''|| clinicIndex.id==null}">
                            号别添加
                        </c:when>
                        <c:otherwise>号别修改</c:otherwise>
                    </c:choose>
                </a>
            </li>
        </ul>
        <section class="panel panel-default">
            <div class="panel-body">
                <div class="col-lg-12">
                    <form:form id="inputForm" data-parsley-validate="" modelAttribute="clinicIndex"
                               onsubmit="return formSaveLoad('mainCenterDiv','inputForm','${ctx}/registration/clinicIndex/save','${ctx}/registration/clinicIndex/index');"
                               method="post" class="form-horizontal">
                        <form:hidden path="id" />
                        <div class="form-group">
                            <label class="col-sm-2 control-label">号别名称：</label>

                            <div class="col-sm-4">
                                <form:input path="name" htmlEscape="false" class="form-control" maxlength="200"
                                            data-parsley-required="true"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <input type="hidden" id="deptId" value="${clinicIndex.deptId}">
                            <label class="col-sm-2 control-label">门诊科室：</label>

                            <div class="col-sm-4">
                                <sys:treeselect selectedParent="true"  method="selectDoctor" isnull="true" id="clinicIndex" name="deptId"
                                                value="${clinicIndex.deptId}" update="false"
                                                labelName="${clinicIndex.deptName}"
                                                labelValue="${clinicIndex.deptName}"
                                                title="科室" url="/sys/orgDept/treeData?outpOrInps=0,2"
                                                cssClass="form-control"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">所属医生：</label>

                            <div class="col-sm-4">
                                <input type="hidden" value="${clinicIndex.doctorId}" id="doctorId">
                                <form:select path="doctorId" id="selectId" class="form-control">
                                    <form:option value="" label="请选择"></form:option>
                                </form:select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">诊疗项目：</label>

                            <div class="col-sm-4">
                                <form:hidden path="clinicItemId" id="clinicItemDict1"/>
                                <form:input path="clinicItemName" id="clinicItemDict" htmlEscape="false"
                                            class="form-control" maxlength="50" data-parsley-required="true"/>

                             </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">备注信息：</label>
                            <div class="col-sm-4">
                                <form:textarea path="remarks" htmlEscape="false" rows="3" maxlength="200" class="form-control"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-offset-2 col-sm-10">
                                <input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存">&nbsp;
                                <input id="btnCancel" class="btn" type="button" value="返 回"
                                       onclick="loadDiv('mainCenterDiv','${ctx}/registration/clinicIndex/index')">
                            </div>
                        </div>
                    </form:form>
                </div>
            </div>
        </section>
    </div>
</div>